package com.riko.comic.module.sys.bean.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Paging {

    private long count;//总数据条数
    private int pageSize;//每页数据条数
    private long pageNumber;//总页面数
    private long page;//当前页
    private final long indexPage = 1;//首页
    private long endPage;//尾页

    public Paging(long count,int pageSize){
        this.count = count;
        this.pageSize = pageSize;
        this.pageNumber = (count%this.pageSize==0)?count/this.pageSize:count/this.pageSize+1;
        this.endPage = this.pageNumber;
    }

    public void setPage(String page) {
        if(page == null){
            //如果前端没有指定page，默认首页
            this.page = indexPage;
        }else {
            int intPage = Integer.parseInt(page);
            if(intPage <= 1){
                //如果page<1,让this.page=1
                this.page = 1;
            }else {
                //如果page>最终页，让this.page=最终页
                this.page = Math.min(intPage, endPage);
            }
        }
    }
}